package com.fuli.app.controller;

import com.fuli.app.common.ActionResult;
import com.fuli.app.util.AliYunUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

import static com.fuli.app.util.AliYunUtils.generateRandom;

@Api(tags = "临时接口")
@RestController
@RequestMapping("/temporary")
public class temporaryController {
    @ApiOperation(value = "获取公共参数")
    @GetMapping("/getByVideoId/{videoId}")
    public ActionResult<String> getByVideoId(@ApiParam("videoId") @PathVariable String videoId) throws Exception {


        // 接口私有参数列表, 不同API请替换相应参数
        Map<String, String> privateParams = new HashMap<>();
        // 视频ID
        privateParams.put("VideoId", videoId);
        // API名称
        privateParams.put("Action", "GetVideoPlayAuth");

        // 接口公有参数列表, 不同API请替换相应参数
        Map<String, String> publicParams = new HashMap<>();
        publicParams.put("Format", "JSON");
        publicParams.put("Version", "2017-03-21");
        publicParams.put("AccessKeyId", AliYunUtils.access_key_id);
        publicParams.put("SignatureMethod", "HMAC-SHA1");
        publicParams.put("Timestamp", AliYunUtils.generateTimestamp());
        publicParams.put("SignatureVersion", "1.0");
        publicParams.put("SignatureNonce", generateRandom());
        if (AliYunUtils.security_token != null && AliYunUtils.security_token.length() > 0) {
            publicParams.put("SecurityToken", AliYunUtils.security_token);
        }
        String URL = AliYunUtils.generateOpenAPIURL(publicParams, privateParams);
        return new ActionResult<>(AliYunUtils.httpGet(URL));
    }

}
